//-----------------------------------------------------------------------------
//
// @file	AnimatedCurves.h
// @brief	AnimatedCurves functionality
// @author	Vinod Melapudi
// @date	01May2011
//
//-----------------------------------------------------------------------------

 
#ifndef _ANIMATEDCURVES_H
#define _ANIMATEDCURVES_H

#include "Mesh.h"
#include "Scene.h"
#include "Texture.h"

class Vector2;


typedef enum OPERATION_MODE
{
	PLOT_CURVE,
	ANIMATE,
};




class Streak
{
public:

	Streak();

	void AddKeyPoint( int x, int y );
	void MoveKeyPoint( int i, int x, int y );
	void RemoveKeyPoint( int i );
	int FindKeyPointAt( int x, int y );

	void Init();
	void Reset();
	void ReCalc();
	void Render( Renderer* renderer );
	void ToggleWireFrame();

	void CalcCurve();
	void ReconstructMeshStrip();

private:
	void CalcMeshLengthInSegments();

public:
	// Points
	bool			m_showCurve;
	vector<Vector2> m_key_points;
	vector<Vector2> m_curve_points;

	vector<Vector2> m_dividing_points;
	vector<Vector2> m_tangent_points;

	int				m_num_bezier_segments;

	Texture*		m_texture;

	// Mesh
	Mesh			m_mesh;
	int				m_mesh_location_on_curve;
	int				m_mesh_length_in_segments;
	float			m_mesh_width;
	float			m_mesh_length;

	// Animation
	float			m_speed;
	int				m_fade_in_frames;
	int				m_fade_out_frames;
};


class AnimatedCurves: public Scene
{
public:
	AnimatedCurves();
	~AnimatedCurves();

	bool Init();
	void Update();
	void Render( Renderer* renderer );
	bool HandleMessage( UINT msg, WPARAM wParam, LPARAM lParam );
	void UnInit();
	void Reset();

	void SetScreenDimension( int w, int h );

private:
	void InitNewStreak();

	OPERATION_MODE mOprMode;

	int m_screen_width;
	int m_screen_height;

	vector<Streak>	m_streaks;
	Streak*			m_current_streak;

	Texture			m_texture;

	int				m_key_point_index_on_move;

	vector<string> m_HUD_text;
};

#endif